﻿using FanaticRock.Core.Helpers;

namespace FanaticRock.Core.Models
{
    ///<summary>歌曲信息。</summary>
    public class Song : ICloneable
    {
        public string Id { get; set; }

        public string Title { get; set; }

        public string OriginTitle { get; set; }

        public string AlbumId { get; set; }

        public string AlbumTitle { get; set; }

        public Uri Uri { get; set; }

        public TimeSpan Duration { get; set; }

        ///<summary>封面的来源。</summary>
        public ResourceSource CoverSource { get; set; } = new  InAudioFileResourceSource();

        public SongMember[] Members { get; set; }

        public Song()
        {

        }

        public Song(Song other)
        {
            Id = other.Id;
            Title = other.Title;
            OriginTitle = other.OriginTitle;
            AlbumId = other.AlbumId;
            AlbumTitle = other.AlbumTitle;
            Uri = other.Uri;
            Duration = other.Duration;
            CoverSource = other.CoverSource.Clone() as ResourceSource;
            Members = ArrayHelper.CloneArray(other.Members);
        }

        public ResourceSource GetCoverSource()
        {
            if (CoverSource == null) return null;
            var cloned = CoverSource.Clone() as ResourceSource;

            if(cloned is InAudioFileResourceSource inAudioFileResourceSource)
            {
                inAudioFileResourceSource.FileUri = Uri;
            }

            return cloned;
        }

        public virtual object Clone()
        {
            return new Song(this);
        }
    }
}
